/**
 * oscP5message by andreas schlegel
 * example shows how to create osc messages.
 * oscP5 website at http://www.sojamo.de/oscP5
 */
 
import oscP5.*;
import netP5.*;


PImage captureImage;
PImage targetImage;
OscP5 oscP5;
NetAddress myRemoteLocation;

void setup() {
  size(400,400);
  frameRate(25);
  /* start oscP5, listening for incoming messages at port 12000 */
  oscP5 = new OscP5(this,7000);
    oscP5.plug(this,"capture","/capture");
    
    targetImage = new PImage(128,128);

}

public void capture(int theX, int theY, int theRadius, String theFile) {
  println("### plug event method. received a message /capture.");
  println("received: "+theX+", "+theY+", "+theRadius+", "+theFile); 
  captureImage = loadImage(theFile); 
  targetImage.copy(captureImage, theX-theRadius, theY-theRadius, theRadius*2, theRadius*2, 0, 0, 128, 128);

}

void draw() {

  
  
  background(0);  
  
    if(targetImage != null) image(targetImage, 0, 0);
}


/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
  /* print the address pattern and the typetag of the received OscMessage */
  //print("### received an osc message.");
  //print(" addrpattern: "+theOscMessage.addrPattern());
  //println(" typetag: "+theOscMessage.typetag());
}
